package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"im_sys/apps/social/rpc/internal/config"
	"im_sys/apps/social/socialmodels"
)

type ServiceContext struct {
	Config config.Config

	FriendRequests socialmodels.FriendRequestsModel
	Friends        socialmodels.FriendsModel
	GroupMembers   socialmodels.GroupMembersModel
	GroupRequests  socialmodels.GroupRequestsModel
	Groups         socialmodels.GroupsModel
}

func NewServiceContext(c config.Config) *ServiceContext {

	conn := sqlx.NewMysql(c.Mysql.DataSource)

	return &ServiceContext{
		Config: c,

		Friends:        socialmodels.NewFriendsModel(conn, c.Cache),
		FriendRequests: socialmodels.NewFriendRequestsModel(conn, c.Cache),
		GroupMembers:   socialmodels.NewGroupMembersModel(conn, c.Cache),
		GroupRequests:  socialmodels.NewGroupRequestsModel(conn, c.Cache),
		Groups:         socialmodels.NewGroupsModel(conn, c.Cache),
	}
}
